常见的几个错误在chromium源码中列出来了

1
2
3
4
5
6
7
8
const char kWarningUnmuteFailed[] =
"Unmuting failed and the element was paused instead because the user "
"didn't interact with the document before. https://goo.gl/xX8pDD";
const char kErrorAutoplayFuncUnified[] =
"play() failed because the user didn't interact with the document first. "
"https://goo.gl/xX8pDD";
const char kErrorAutoplayFuncMobile[] =
"play() can only be initiated by a user gesture.";

文档 写的相对比较清楚,三个条件

  • 静音的自动播放都可以
  • 带声音的播放有条件
    • 用户在当前域名有交互(点击、触摸等等)的可以自动播
    • 在桌面端的Chrome中,符合用户偏好历史的可以自动播,在 chrome://media-engagement/ 可以看
    • 移动端用户加入首屏的站点或者桌面端已安装的PWA可以自动播
  • 顶层的Frame可以允许子级iframe的带声音自动播放,用iframeallow="autoplay"属性,前提是顶层frame满足带声音播放的条件

检测方法

可参考 这个项目(不是很新的) 的DemoPage

最后更新: 2022年03月02日 03:32

原始链接: http://rawbin-.github.io/browser/2018-12-13-chrome-autoplay/

× 赞赏这个人~
打赏二维码